home *** CD-ROM | disk | FTP | other *** search
- bitstr.doc: documentation for the "bitstr" (v1.20) C routines
-
- This is the second release of the "bitstring" routines.
- The routines included in this .ZIP file are intended to replace the
- previous release of the same routines in the file bitstr.arc. These C routines
- arose from an article on pages 34-43 of the April, 1989 issue of Computer
- Language Magazine. I thought the routines given there were somewhat
- inefficient, and so I took the idea and rewrote the functions into much
- simpler (and, perhaps, less portable) versions.
- The idea behind the routines is to implement, in C, a way to store a
- true, numberable array of "boolean" values, without using entire characters or
- even bitfields (whose values must be individually named-- not usable in an
- indexed-array fashion). The array is made up of unsigned ints; the int is, on
- the 8086, 8088, and the 80286 and 80386 in real mode, the same width in bits
- (16) as the chip's data bus, making bitstring bit shifting operations
- operate more quickly. Each bit in an unsigned int can become one boolean
- value. Therefore, one unsigned int can store sixteen bitstring values.
- Unlike the last version (1.10) of these routines, there are now two ways
- to use the functions: as true, linkable functions, or as preprocessor
- replacements using #define statements in a single header file. The primary
- difference between the two is that the macro versions are good for use when
- speed, not size, is of utmost importance: No function-calling overhead is
- incurred, but replacing the macro at more than a few locations is very
- space-consuming. On the other hand, the function versions are slightly
- slower, but a function call uses less space than the macro expansion.
- In general, for small (one-file) projects I use the macro versions, and for
- large programs I link in the functions.
- There are three bitstring routines (their prototypes are also shown):
-
- void clear_bit(unsigned int *bitstr, int bit)
- This routine clears to false or 0 a bit in a bitstring. The "bitstr"
- parameter is a pointer to the bitstring array of unsigned ints. The
- "bit" parameter specifies the bit to be operated upon.
-
- void set_bit(unsigned int *bitstr, int bit)
- The parameters for this routine are the same as for clear_bit(), except
- that the "bit" bit in the "bitstr" array is set to true or 1.
-
- int test_bit(unsigned int *bitstr, int bit)
- The parameters here are the same as before. test_bit() returns an
- integer that is zero if the "bit" bit is clear/false/0, and non-zero if
- "bit" is set/true/1.
-
- Note that the routines use a "bit" parameter that starts counting at 0,
- not 1.
- The bitstring routines are designed to work with pointers to one or more
- unsigned ints. This makes it possible to use more than 16 values in one array
- by declaring an array of unsigned ints, and passing the address of the first
- one as the first parameter in calls to these routines. The routines
- automatically choose the proper unsigned int to work on based on the value of
- the "bit" parameter-- if the value is over 15, modulo division is used to
- bring it to a value between 0 and 15, and the position in memory is
- incremented accordingly.
- Example:
-
-
- #include <stdio.h>
- #include "bitstr_h.h" /* or bitstr_f.h and link-in bitstr_f.c */
-
- unsigned int data[2]; /* allows use of up to 32 values */
-
- void main(void)
- {
- register int i;
-
- for (i=0; i<22; i++) set_bit(&data[0],i); /* pass address of int array */
- for (i=0; i<32; i++) if (test_bit(&data[0],i)) printf("bit %d is set\n",i);
- for (i=0; i<22; i++) clear_bit(&data[0],i);
- }
-
-
- Here are descriptions of the files included in this release:
-
- bitstr.doc: What else could you be looking at?
-
- bitstr_f.h, bitstr_f.c: These two files are to be used just as in version
- 1.10, i.e. compile bitstr_f.c under any needed memory model, then #include
- "bitstr_f.h" in your source code, and link the compiled bitstr_f.obj with your
- executable program.
-
- bitstr_h.h: This is the alternate way of using the bitstring routines:
- All you need to do here is to #include "bitstr_h.h" in any source files that
- use the bitstring routines, then just leave it-- there is no need to compile
- and link bitstr_f.c, as the routines are replaced in your source by the C
- preprocessor. You should not include both bitstr_f.h and bitstr_h.h at the
- same time: Use either the #include "bitstr_h.h" method, or the #include
- "bitstr_f.h", compile-and-link bitstr_f.c, method, but not both.
-
- In the files, the macro US is #defined to be 16, the width in bits of the
- CPU. This will work for 8086, 8088, and 80286 applications (as well as the
- 80386 in real mode). Another macro, HEX1, is #defined to be (unsigned)
- 0x0001. This macro represents a single set bit at the rightmost position of
- the integer, and is used in the routines to allow a single bit to be shifted
- around and logically ANDed or ORed.
-
- I have strived to make these routines as bug-free as possible, and they
- have worked well in several programming projects. However, if you do find an
- error (or just want to make comments, etc.), I can be contacted:
-
- Erik Mavrinac
- CIS [73507,3523]
-
- Please note that the address in bitstr.arc 1.10 is no longer valid: I prefer
- electronic mail, because I am moving frequently now to and from college.
-
- revision history:
- v1.00: The original routines emerged.
- v1.10: Fixes for errors in the entire concept as implemented in v1.00.
- Also, original documentation file written and bundled for upload to
- CIS.
- v1.20: What you have here. The single lines of the original functions began
- to appear simple enough to put into macros. Also, documentation
- changes were made.
-
-
-
- ----------------end-of-author's-documentation---------------
-
- Software Library Information:
-
- This disk copy provided as a service of
-
- Public (software) Library
-
- We are not the authors of this program, nor are we associated
- with the author in any way other than as a distributor of the
- program in accordance with the author's terms of distribution.
-
- Please direct shareware payments and specific questions about
- this program to the author of the program, whose name appears
- elsewhere in this documentation. If you have trouble getting
- in touch with the author, we will do whatever we can to help
- you with your questions. All programs have been tested and do
- run. To report problems, please use the form that is in the
- file PROBLEM.DOC on many of our disks or in other written for-
- mat with screen printouts, if possible. PsL cannot debug pro-
- programs over the telephone, though we can answer questions.
-
- Disks in the PsL are updated monthly, so if you did not get
- this disk directly from the PsL, you should be aware that the
- files in this set may no longer be the current versions. Also,
- if you got this disk from another vendor and are having prob-
- lems, be aware that some files may have become corrupted or
- lost by that vendor. Get a current, working disk from PsL.
-
- For a copy of the latest monthly software library newsletter
- and a list of the 2,000+ disks in the library, call or write
-
- Public (software) Library
- P.O.Box 35705 - F
- Houston, TX 77235-5705
-
- 1-800-2424-PSL
- MC/Visa/AmEx/Discover
-
- Outside of U.S. or in Texas
- or for general information,
- Call 1-713-524-6394
-
- PsL also has an outstanding
- catalog for the Macintosh.
-